import { reactive, onMounted } from "vue";
import axios, { AxiosError } from "axios";;

export default function useDog() {
    let dogList = reactive<string[]>([]);

    async function getDog() {
        try {
            let { data } = await axios.get(
                'https://d1og.ceo/api/breed/pembroke/images/random'
            )
            //放入列表
            dogList.push(data.message)
        } catch (error){

            // 处理错误
            const err = <AxiosError>error
            console.log(err.message)
        }
    }

    onMounted(() => {
        getDog();
    })

    //向外暴露数据
    return { dogList, getDog }
}